# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import time

import scrapy
# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
from scrapy.pipelines.images import ImagesPipeline


# class ImgproPipeline:
#     def process_item(self, item, spider):
#         return item

# 自己分装管道类，用来持久化存储图片等二进制文件
class ImagsPipeline(ImagesPipeline):

    # 可以根据图片地址对图片数据进行请求
    def get_media_requests(self, item, info):
        # return super().get_media_requests(item, info)
        time.sleep(0.1)
        yield scrapy.Request(item['src'])

    # 指定图片名称
    def file_path(self, request, response=None, info=None, *, item=None):
        imgName =item['title']+'.'+str(request.url).split('.')[-1]
        return imgName

    def item_completed(self, results, item, info):
        return item



if __name__=="__main__":
    url="https://scpic.chinaz.net/files/default/imgs/2024-08-07/c9b3ebad6cde21f2.jpg"
    split___ = url.split('.')[-1]
    print(split___)
